﻿using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IISLogAnalyzer
{
    public static class TraverseDirectoryFiles
    {
        public static ConcurrentQueue<string> stringQueue = new ConcurrentQueue<string>();
        public static List<string> filePaths = new List<string>();
        // 线程安全的进度计数器  
        public static int totalFiles { get { return filePaths.Count; } }
        public static int filePathsCountIindex = 0;
        public static int databaseProgress = 0;
        public static int databaseProgressTotal = 0;

        // 锁对象，用于确保线程安全地更新进度  
        public static readonly object SyncRoot = new object();

        public static void TraverseDirectory(string path)
        {
            try
            {
                // 检查路径是否存在  
                if (!Directory.Exists(path))
                {
                    return;
                }


                // 获取目录下的所有文件路径  
                string[] files = Directory.GetFiles(path, "*.log");

                foreach (string file in files)
                {
                    filePaths.Add(file);
                }

                // 获取目录下的所有子目录  
                string[] subDirectories = Directory.GetDirectories(path);

                // 递归遍历子目录  
                foreach (string subDirectory in subDirectories)
                {
                    TraverseDirectory(subDirectory);
                }
            }
            catch
            {
                return;
            }
        }
    }
}
